prepare_conjoint <- function(data, condition, by = NULL){
  
  if(condition == "parliament" & is.null(by)){
    cj_parliament <- cregg::cj(data, f1, id = ~id) %>% 
      mutate(
        level = ifelse(estimate == 0, paste0("(Baseline = ", level, ")"), as.character(level))
      )
    
    for(i in 1:nrow(cj_parliament)){
      if(i == 1){
        cj_parliament <- add_row(cj_parliament, level = paste(cj_parliament$feature[i], ":", sep = ""))
      }else if(cj_parliament$feature[i] != cj_parliament$feature[i-1]){
        cj_parliament <- add_row(cj_parliament, level = paste(cj_parliament$feature[i], ":", sep = ""))
      }
    }
    
    cj_parliament$level <- ifelse(
      !is.na(cj_parliament$estimate), paste("    ", cj_parliament$level, sep = ""), cj_parliament$level
    )
    
    cj_parliament$level <-  factor(cj_parliament$level, 
                                   levels = c("Legislative checks:", 
                                              "    (Baseline = Work with Parliament)", 
                                              "    Shut down Parliament",
                                              "Lockdown policy:", 
                                              "    (Baseline = Lockdown ended now)", 
                                              "    Lockdown until fewer deaths",
                                              "    Lockdown until vaccine",
                                              "Economic aid policy:", 
                                              "    (Baseline = Mostly to businesses)", 
                                              "    Mostly to workers",
                                              "    Basic income",
                                              "Party:",
                                              "    (Baseline = Conservative)",
                                              "    Liberal",
                                              "    New Democrat",
                                              "Gender:",
                                              "    (Baseline = Male)",
                                              "    Female",
                                              "Political experience:",
                                              "    (Baseline = No political experience)",
                                              "    Mayor", 
                                              "    Member of Parliament", 
                                              "    Member of provincial legislature",
                                              "Age:",
                                              "    (Baseline = 37)",
                                              "    39",
                                              "    43",
                                              "    45",
                                              "    52",
                                              "    57",
                                              "    61",
                                              "    66",
                                              "    71",
                                              "    75"))
    
    return(cj_parliament)
  }
  
  else if(condition == "courts" & is.null(by)){
    
    cj_courts <- cregg::cj(data, f2, id = ~id) %>% 
      mutate(
        level = ifelse(estimate == 0, paste0("(Baseline = ", level, ")"), as.character(level))
      )
    
    for(i in 1:nrow(cj_courts)){
      if(i == 1){
        cj_courts <- add_row(cj_courts, level = paste(cj_courts$feature[i], ":", sep = ""))
      }else if(cj_courts$feature[i] != cj_courts$feature[i-1]){
        cj_courts <- add_row(cj_courts, level = paste(cj_courts$feature[i], ":", sep = ""))
      }
    }
    
    cj_courts$level <- ifelse(
      !is.na(cj_courts$estimate), paste("    ", cj_courts$level, sep = ""), cj_courts$level
    )
    
    cj_courts$level <-  factor(cj_courts$level, 
                               levels = c("Judicial checks:", 
                                          "    (Baseline = Obey courts)", 
                                          "    Ignore courts",
                                          "Lockdown policy:", 
                                          "    (Baseline = Lockdown ended now)", 
                                          "    Lockdown until fewer deaths",
                                          "    Lockdown until vaccine",
                                          "Economic aid policy:", 
                                          "    (Baseline = Mostly to businesses)", 
                                          "    Mostly to workers",
                                          "    Basic income",
                                          "Party:",
                                          "    (Baseline = Conservative)",
                                          "    Liberal",
                                          "    New Democrat",
                                          "Gender:",
                                          "    (Baseline = Male)",
                                          "    Female",
                                          "Political experience:",
                                          "    (Baseline = No political experience)",
                                          "    Mayor", 
                                          "    Member of Parliament", 
                                          "    Member of provincial legislature",
                                          "Age:",
                                          "    (Baseline = 37)",
                                          "    39",
                                          "    43",
                                          "    45",
                                          "    52",
                                          "    57",
                                          "    61",
                                          "    66",
                                          "    71",
                                          "    75"))
    
    return(cj_courts)
  }
  
  else if(condition == "parliament" & !(is.null(by))){
    cj_parliament <- cregg::cj(data, f1, id = ~id, by = by) %>% 
      mutate(
        level = ifelse(estimate == 0, paste0("(Baseline = ", level, ")"), as.character(level))
      )
    
    for(i in 1:nrow(cj_parliament)){
      if(i == 1){
        cj_parliament <- add_row(cj_parliament, level = paste(cj_parliament$feature[i], ":", sep = ""))
      }else if(cj_parliament$feature[i] != cj_parliament$feature[i-1]){
        cj_parliament <- add_row(cj_parliament, level = paste(cj_parliament$feature[i], ":", sep = ""))
      }
    }
    
    cj_parliament$level <- ifelse(
      !is.na(cj_parliament$estimate), paste("    ", cj_parliament$level, sep = ""), cj_parliament$level
    )
    
    cj_parliament$level <-  factor(cj_parliament$level, 
                                   levels = c("Legislative checks:", 
                                              "    (Baseline = Work with Parliament)", 
                                              "    Shut down Parliament",
                                              "Lockdown policy:", 
                                              "    (Baseline = Lockdown ended now)", 
                                              "    Lockdown until fewer deaths",
                                              "    Lockdown until vaccine",
                                              "Economic aid policy:", 
                                              "    (Baseline = Mostly to businesses)", 
                                              "    Mostly to workers",
                                              "    Basic income",
                                              "Party:",
                                              "    (Baseline = Conservative)",
                                              "    Liberal",
                                              "    New Democrat",
                                              "Gender:",
                                              "    (Baseline = Male)",
                                              "    Female",
                                              "Political experience:",
                                              "    (Baseline = No political experience)",
                                              "    Mayor", 
                                              "    Member of Parliament", 
                                              "    Member of provincial legislature",
                                              "Age:",
                                              "    (Baseline = 37)",
                                              "    39",
                                              "    43",
                                              "    45",
                                              "    52",
                                              "    57",
                                              "    61",
                                              "    66",
                                              "    71",
                                              "    75"))
    
    return(cj_parliament)
  }
  
  else if(condition == "courts" & !(is.null(by))){
    cj_courts <- cregg::cj(data, f2, id = ~id, by = by) %>% 
      mutate(
        level = ifelse(estimate == 0, paste0("(Baseline = ", level, ")"), as.character(level))
      )
    
    for(i in 1:nrow(cj_courts)){
      if(i == 1){
        cj_courts <- add_row(cj_courts, level = paste(cj_courts$feature[i], ":", sep = ""))
      }else if(cj_courts$feature[i] != cj_courts$feature[i-1]){
        cj_courts <- add_row(cj_courts, level = paste(cj_courts$feature[i], ":", sep = ""))
      }
    }
    
    cj_courts$level <- ifelse(
      !is.na(cj_courts$estimate), paste("    ", cj_courts$level, sep = ""), cj_courts$level
    )
    
    cj_courts$level <-  factor(cj_courts$level, 
                               levels = c("Judicial checks:", 
                                          "    (Baseline = Obey courts)", 
                                          "    Ignore courts",
                                          "Lockdown policy:", 
                                          "    (Baseline = Lockdown ended now)", 
                                          "    Lockdown until fewer deaths",
                                          "    Lockdown until vaccine",
                                          "Economic aid policy:", 
                                          "    (Baseline = Mostly to businesses)", 
                                          "    Mostly to workers",
                                          "    Basic income",
                                          "Party:",
                                          "    (Baseline = Conservative)",
                                          "    Liberal",
                                          "    New Democrat",
                                          "Gender:",
                                          "    (Baseline = Male)",
                                          "    Female",
                                          "Political experience:",
                                          "    (Baseline = No political experience)",
                                          "    Mayor", 
                                          "    Member of Parliament", 
                                          "    Member of provincial legislature",
                                          "Age:",
                                          "    (Baseline = 37)",
                                          "    39",
                                          "    43",
                                          "    45",
                                          "    52",
                                          "    57",
                                          "    61",
                                          "    66",
                                          "    71",
                                          "    75"))
    
    return(cj_courts)
  }
  
  
}